package org.example.test_qlexpress.function;

import com.ql.util.express.Operator;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

public class AvgFunction extends Operator {
    public Object executeInner(Object[] objects) throws Exception {
        if (objects == null || objects.length == 0) {
            return BigDecimal.ZERO;
        }
        BigDecimal sum = (BigDecimal) new SumFunction().executeInner(objects);
        BigDecimal total = BigDecimal.valueOf(objects.length);
        return sum.divide(total, 4, RoundingMode.HALF_UP);
    }
}
